from tkinter import *
import pyautogui
import time

WINDOW_WIDTH = 800
WINDOW_HEIGHT = 600

MOUSE_POS = [[0] * 2 for _ in range(11)]


def window_size(width, height):
    root = Tk()
    root.title('text program')
    x = (root.winfo_screenwidth() - width) / 2
    y = (root.winfo_screenheight() - height) / 2
    root.geometry("%dx%d+%d+%d" % (width, height, x, y - 30))
    app = Application(master=root)
    root.mainloop()


class Application(Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.createWidget()

    def createWidget(self):
        # 创建组件

        self.type = IntVar()
        self.type.set(-1)
        self.type0 = Radiobutton(self, text="高V", value=0, variable=self.type)
        self.type1 = Radiobutton(self, text="高A", value=1, variable=self.type)
        self.type0.pack(side="left")
        self.type1.pack(side="left")

        self.place = IntVar()
        self.place.set(-1)
        self.place0 = Radiobutton(self, text="东", value=0, variable=self.place)
        self.place1 = Radiobutton(self, text="杭", value=1, variable=self.place)
        self.place2 = Radiobutton(self, text="开", value=2, variable=self.place)
        self.place3 = Radiobutton(self, text="徐", value=3, variable=self.place)
        self.place0.pack(side="left")
        self.place1.pack(side="left")
        self.place2.pack(side="left")
        self.place3.pack(side="left")


def getCursorPos(i):
    MOUSE_POS[i][0], MOUSE_POS[i][1] = pyautogui.position()


def moveMouseTo(x, y, time):
    pyautogui.moveTo(x, y, duration=time)


def moveMouseAndClick(x, y, t, f):
    pyautogui.click(x, y, 1, t, button=f)


def openMap():
    pyautogui.press('m')


def delay(t):
    time.sleep(t)


def findWindow():
    windows = pyautogui.getWindowsWithTitle('微信')
    if(len(windows)) == 0:
        raise Exception('微信窗口未找到')
    return windows[0]


if __name__ == '__main__':
    # getCursorPos(0)
    #
    # print(MOUSE_POS)
    # moveMouseAndClick(525, 1055, 0, 'left')
    # delay(0.5)
    # openMap()

    wxWindow = findWindow()
    wxWindow.activate()
